package com.im.project.webSocket;

import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * 消息发送工厂
 *
 * @author yunZhouJiaDi
 */
public class ProcessFactory<T> {
    public static <T> void process(T data, String userId) {
        Channel channel = UserChannelCtxMap.USER_CHANNEL_MAP.get(userId);
        if (channel == null) {
            return;
        }
        TextWebSocketFrame userTextWebSocketFrame = new TextWebSocketFrame(JSON.toJSONString(data));
        channel.writeAndFlush(userTextWebSocketFrame);
    }
}
